﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Main.Master" AutoEventWireup="true"
    CodeBehind="RevenueMachineAccountManagement-Invoice.aspx.cs" Inherits="NetDon.OA.Portal.Finance.RevenueMachineAccountManagement_Invoice" %>

<%@ Import Namespace="NetDon.OA.Interface" %>
<%@ Import Namespace="NetDon.OA.Portal" %>
<%@ Import Namespace="NetDon.Utilities" %>
<%@ Register Src="../Controls/GridPager.ascx" TagName="GridPager" TagPrefix="uc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <script language="javascript" type="text/javascript">
        var userDialogSize = { width: 800, height: window.top.$common.getClientBounds().height - 200 };



        function viewOrder(sender, args) {
            var orderId = $attr(sender.get_selectedRow(), 'Id');
            $dialog('<%= ResolveUrl("~/Finance/InvoiceEdit.aspx")%>?Id=' + orderId, userDialogSize, function (result) {
                if (result) {
                    $get('<%=btnReload.ClientID %>').click();
                }
            });
        }


        function modifyOrder(orderId) {
            $dialog('<%=ResolveUrl("~/Finance/InvoiceEdit.aspx") %>?Id=' + orderId, userDialogSize, function (result) {
                if (result) {
                    $get('<%=btnReload.ClientID %>').click();
                }
            });
        }

        function chooseOrderForInvoice(orderId) {
            var idArray = new Array();
            idArray.push(orderId);
            $dialog('<%=ResolveUrl("~/Finance/ChooseOrderForInvoice.aspx") %>?Id=' + orderId, userDialogSize, function (result) {
                if (result) {
                    var data = JSON.parse(result);
                    batchConfirmOrder(data);
                }
            }, { Ids: idArray.toString() });
        }

        function batchConfirmOrder(data) {

            $dialog('<%=ResolveUrl("~/Finance/ConfirmInvoice.aspx") %>' , userDialogSize, function (result) {
                if (result) {

                    $get('<%=btnReload.ClientID %>').click();
                }
            }, { IssuingOrderIds: data.IssuingOrderIds, RevenueMachineAccountIds: data.RevenueMachineAccountIds, StateofAccountAmount: data.TotalStateofAccountAmount });
        }


        function deleteOrderInvoice(orderId) {
            $confirm("确定要删除该笔开票吗？", function (result) {
                if (result) {
                    $text($get('<%=fieldOrderId.ClientID %>'), orderId);
                    $get('<%=btnHiddenDelete.ClientID %>').click();
                }
            });
        }


  
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <asp:UpdatePanel ID="UpdatePanelFlow" runat="server">
        <ContentTemplate>
            <asp:Panel ID="Panel1" runat="server" DefaultButton="btnSearch">
                <table border="0" cellpadding="0" cellspacing="0">
                    <tr>
                        <td>
                            <NetDon:FormPanel ID="PanelCondition" runat="server" CaptionAlign="NotSet" RepeatColumns="2">
                                <Items>
                                    <NetDon:FormItem HeaderText="客户">
                                        <ContentTemplate>
                                            <asp:DropDownList ID="ddlCustomer" runat="server" DataSourceID="ObjectDataSourceCustomers"
                                                DataTextField="CustomerName" DataValueField="CustomerId" AppendDataBoundItems="true">
                                            </asp:DropDownList>
                                            <asp:ObjectDataSource ID="ObjectDataSourceCustomers" runat="server" OldValuesParameterFormatString="original_{0}"
                                                SelectMethod="RetrieveCustomers" TypeName="NetDon.OA.Business.MiscDataSource">
                                                <SelectParameters>
                                                    <asp:Parameter Name="areaId" />
                                                </SelectParameters>
                                            </asp:ObjectDataSource>
                                        </ContentTemplate>
                                    </NetDon:FormItem>
                                    <NetDon:FormItem HeaderText="线路分类">
                                        <ContentTemplate>
                                            <asp:DropDownList ID="ddlRouteTypeId" DataSourceID="ddsRouteTypeId" AppendDataBoundItems="True"
                                                runat="server" DataTextField="Name" DataValueField="Value">
                                            </asp:DropDownList>
                                            <NetDon:DictionaryDataSource ID="ddsRouteTypeId" runat="server" CategoryName="线路分类"
                                                EmptyItemType="Select">
                                            </NetDon:DictionaryDataSource>
                                        </ContentTemplate>
                                    </NetDon:FormItem>
                                    <NetDon:FormItem HeaderText="开票日期">
                                        <ContentTemplate>
                                            <asp:TextBox ID="txtConfirmInvoiceDateStart" runat="server" Width="75px"></asp:TextBox>
                                            <asp:CalendarExtender ID="CalendarExtender3" runat="server" Enabled="True" TargetControlID="txtConfirmInvoiceDateStart"
                                                Format="yyyy-MM-dd">
                                            </asp:CalendarExtender>
                                            <asp:Label ID="Label2" runat="server" Text="~" Style="margin-left: 5px; margin-right: 6px"></asp:Label>
                                            <asp:TextBox ID="txtConfirmInvoiceDateEnd" runat="server" Width="75px"></asp:TextBox>
                                            <asp:CalendarExtender ID="CalendarExtender4" runat="server" Enabled="True" TargetControlID="txtConfirmInvoiceDateEnd"
                                                Format="yyyy-MM-dd">
                                            </asp:CalendarExtender>
                                        </ContentTemplate>
                                    </NetDon:FormItem>
                                    <NetDon:FormItem HeaderText="发票号码">
                                        <ContentTemplate>
                                            <asp:TextBox ID="txtInvoiceNo" runat="server"></asp:TextBox>
                                        </ContentTemplate>
                                    </NetDon:FormItem>
                                    <NetDon:FormItem HeaderText="承运公司">
                                        <ContentTemplate>
                                            <asp:DropDownList ID="ddlCompany" runat="server" DataSourceID="ObjectDataSourceCompany"
                                                DataTextField="CompanyName" DataValueField="CompanyId" AppendDataBoundItems="true">
                                            </asp:DropDownList>
                                            <asp:ObjectDataSource ID="ObjectDataSourceCompany" runat="server" OldValuesParameterFormatString="original_{0}"
                                                SelectMethod="RetrieveCompanies" TypeName="NetDon.OA.Business.MiscDataSource">
                                            </asp:ObjectDataSource>
                                        </ContentTemplate>
                                    </NetDon:FormItem>
                                </Items>
                            </NetDon:FormPanel>
                        </td>
                        <td valign="bottom">
                            <asp:Button ID="btnSearch" SkinID="Button60" runat="server" OnClick="btnSearch_Click"
                                Text="查询"></asp:Button>
                            <asp:Button ID="btnReload" runat="server" SkinID="Hidden" OnClick="btnReload_Click" />
                            <asp:Button ID="btnBatchConfirm" SkinID="Button60" runat="server" Text="开票"></asp:Button>
                        </td>
                    </tr>
                </table>
            </asp:Panel>
            <div style="margin-top: 10px">
                <NetDon:GridView ID="gridOrderList" runat="server" AutoGenerateColumns="False" AllowSorting="true"  OnClientRowDblClick="viewOrder"
                    DataKeyNames="Id" OnRowDataBound="gridOrderList_RowDataBound" OnRowDetailCreated="gridProductList_RowDetailCreated">
                    <Columns>
                        <NetDon:TemplateField HeaderText="线路分类" SortExpression="RouteTypeId">
                            <ItemTemplate>
                                <%#GetDictionaryItemName(Eval("RouteTypeId"))%>
                            </ItemTemplate>
                        </NetDon:TemplateField>
                        <NetDon:BoundField HeaderText="客户" DataField="CustomerName" SortExpression="CustomerName">
                        </NetDon:BoundField>
                        <NetDon:BoundField HeaderText="开票日期" DataField="ConfirmInvoiceDate" DataFormatString="{0:yyyy-MM-dd}"
                            SortExpression="ConfirmInvoiceDate">
                        </NetDon:BoundField>
                        <NetDon:BoundField HeaderText="发票号码" DataField="InvoiceNO" SortExpression="InvoiceNO">
                        </NetDon:BoundField>
                        <NetDon:TemplateField HeaderText="发票类型" SortExpression="InvoiceType">
                            <ItemTemplate>
                                <%#GetDictionaryItemName(Eval("InvoiceType"))%>
                            </ItemTemplate>
                        </NetDon:TemplateField>
                        <NetDon:BoundField HeaderText="应收日期" DataField="AccountsReceivableDate" DataFormatString="{0:yyyy-MM-dd}"
                            SortExpression="AccountsReceivableDate">
                        </NetDon:BoundField>
                        <NetDon:TemplateField HeaderText="币种" SortExpression="InvoiceCurrencyType">
                            <ItemTemplate>
                                <%#GetDictionaryItemName(Eval("InvoiceCurrencyType"))%>
                            </ItemTemplate>
                        </NetDon:TemplateField>
                        <NetDon:TemplateField HeaderText="对账金额(￥)" SortExpression="StateofAccountAmount">
                            <ItemTemplate>
                                <%#!MiscUtilities.IsNullOrEmpty(Eval("StateofAccountAmount")) ? ((Decimal)Eval("StateofAccountAmount")).ToString("#,###.00") : ""%>
                            </ItemTemplate>
                            <ItemStyle HorizontalAlign="Right"></ItemStyle>
                        </NetDon:TemplateField>
                        <NetDon:TemplateField HeaderText="开票金额(￥)" SortExpression="InvoiceAmount">
                            <ItemTemplate>
                                <%#!MiscUtilities.IsNullOrEmpty(Eval("InvoiceAmount")) ? ((Decimal)Eval("InvoiceAmount")).ToString("#,###.00") : ""%>
                            </ItemTemplate>
                            <ItemStyle HorizontalAlign="Right"></ItemStyle>
                        </NetDon:TemplateField>
                        <NetDon:BoundField HeaderText="开票备注" DataField="InvoiceDescription" SortExpression="InvoiceDescription">
                        </NetDon:BoundField>
                        <NetDon:BoundField HeaderText="更新时间" DataField="LastUpdatedDate" SortExpression="LastUpdatedDate"
                            DataFormatString="{0:yyyy-MM-dd}">
                        </NetDon:BoundField>
                        <NetDon:BoundField HeaderText="更新人" SortExpression="LastUpdatedBy" DataField="UserName">
                        </NetDon:BoundField>
                        <NetDon:TemplateField HeaderText="操作" ItemStyle-Width="50px">
                            <ItemTemplate>
                                
                                  <asp:ImageButton ID="btnEdit1" runat="server" SkinID="Modify" ImageAlign="AbsMiddle"
                                    CausesValidation="false" />
                                <asp:ImageButton ID="btnDelete" runat="server" SkinID="Delete" />

                            </ItemTemplate>
                        </NetDon:TemplateField>
                    </Columns>
                    <DetailSettings HeaderText="订单明细" ColumnWidth="100px" CollapseText="隐藏" ExpandText="查看"
                        ExpandImageUrl="~/Images/Button/expand.jpg" CollapseImageUrl="~/Images/Button/collapse.jpg"
                        TargetControlID="pnlInvoiceOrder">
                    </DetailSettings>
                </NetDon:GridView>
                <uc1:GridPager ID="PageQueryAdapter1" runat="server" TargetControlID="gridOrderList"
                    OnPerformGetCondition="PageQueryAdapter1_PerformGetCondition" OnPerformGetRecordCount="PageQueryAdapter1_PerformGetRecordCount"
                    OnPerformGetPageData="PageQueryAdapter1_PerformGetPageData" />
            </div>
            <asp:Panel ID="pnlInvoiceOrder" runat="server" Visible="false" ScrollBars="None"
                BorderColor="White">
                <div style="width: 900px; overflow-x: auto;">
                    <asp:GridView ID="grdInvoiceOrder" BorderWidth="0px" CellPadding="0" CellSpacing="0"
                        Width="100%" AutoGenerateColumns="false" runat="server" OnRowDataBound="grdInvoiceOrder_RowDataBound">
                        <Columns>
                            <asp:BoundField HeaderText="订单编号" DataField="OrderCode" SortExpression="OrderCode">
                            </asp:BoundField>
                            <asp:BoundField HeaderText="实发货日期" DataField="ActualShippingDate" SortExpression="ActualShippingDate"
                                DataFormatString="{0:yyyy-MM-dd}"></asp:BoundField>
                            <asp:BoundField HeaderText="运输计划号" DataField="TransportationPlanCode" SortExpression="TransportationPlanCode">
                            </asp:BoundField>
                            <asp:TemplateField HeaderText="送货城市">
                                <ItemTemplate>
                                    <%#Server.HtmlEncode(GetCityName(Eval("IssuingOrderId")))%>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="送货地址">
                                <ItemTemplate>
                                    <asp:Label ID="lblMessage" runat="server" Text='<%# GetShortDeliveryAddress(Eval("IssuingOrderId")) %>'
                                        Style="cursor: pointer" ToolTip='<%# GetDeliveryAddress(Eval("IssuingOrderId")) %>'></asp:Label>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="实际装车材积" SortExpression="ActualOrderVolumn">
                                <ItemTemplate>
                                    <%#!MiscUtilities.IsNullOrEmpty(Eval("ActualOrderVolumn")) ? Convert.ToDecimal(Eval("ActualOrderVolumn")).ToString("#,###.00") : ""%>
                                </ItemTemplate>
                                <ItemStyle HorizontalAlign="Right"></ItemStyle>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="实际装车重量" SortExpression="ActualOrderWeight">
                                <ItemTemplate>
                                    <%#!MiscUtilities.IsNullOrEmpty(Eval("ActualOrderWeight")) ? Convert.ToInt32(Eval("ActualOrderWeight")).ToString("#,###") : ""%>
                                </ItemTemplate>
                                <ItemStyle HorizontalAlign="Right"></ItemStyle>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="实际装车数量" SortExpression="ActualOrderQuantity">
                                <ItemTemplate>
                                    <%#!MiscUtilities.IsNullOrEmpty(Eval("ActualOrderQuantity")) ? Convert.ToInt32(Eval("ActualOrderQuantity")).ToString("#,###") : ""%>
                                </ItemTemplate>
                                <ItemStyle HorizontalAlign="Right"></ItemStyle>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="营业收入(￥)" SortExpression="Revenues">
                                <ItemTemplate>
                                    <%#!MiscUtilities.IsNullOrEmpty(Eval("Revenues")) ? ((Decimal)Eval("Revenues")).ToString("#,###.00") : ""%>
                                </ItemTemplate>
                                <ItemStyle HorizontalAlign="Right"></ItemStyle>
                            </asp:TemplateField>
                            <asp:TemplateField HeaderText="营业总收入(￥)" SortExpression="TotalRevenues">
                                <ItemTemplate>
                                    <%#!MiscUtilities.IsNullOrEmpty(Eval("TotalRevenues")) ? ((Decimal)Eval("TotalRevenues")).ToString("#,###.00") : ""%>
                                </ItemTemplate>
                                <ItemStyle HorizontalAlign="Right"></ItemStyle>
                            </asp:TemplateField>
                            <%--           <asp:TemplateField HeaderText="操作" ItemStyle-Width="100px">
                                <ItemTemplate>
                                    <asp:ImageButton ID="btnDetails" Style="margin-left: 5px" ToolTip="Details" runat="server"
                                        SkinID="ViewDetail" ImageAlign="AbsMiddle" CausesValidation="false" />
                                    <asp:ImageButton ID="btnDelete" runat="server" SkinID="Delete" />
                                </ItemTemplate>
                            </asp:TemplateField>--%>
                        </Columns>
                        <HeaderStyle CssClass="test" />
                        <RowStyle CssClass="test" />
                        <AlternatingRowStyle CssClass="GridRow1" />
                    </asp:GridView>
                </div>
            </asp:Panel>
            <asp:HiddenField ID="fieldOrderId" runat="server" />
            <asp:Button ID="btnHiddenDelete" runat="server" OnClick="btnDelete_Click" Text="Delete"
                SkinID="Hidden" />
        </ContentTemplate>
    </asp:UpdatePanel>
    <script type="text/javascript">

        function pageLoad() {
            setTimeout(function () {
                function showDetail(index) {
                    var grid = $find('<%=gridOrderList.ClientID%>');
                    if (grid._rows.length <= index) return;
                    var row = grid._rows[index];
                    var elements = row.getElementsByTagName("input"); //the last input is the details loading 
                    grid.showDetail(index, elements[elements.length - 1], function () {
                        showDetail(index + 1);
                    });
                }

                showDetail(0);

            }, 0);
        }

    </script>
</asp:Content>
